import axios from 'axios';
import { PageParam } from '@/api/global';

const BASE_URL = '/orange-system/v1.0/msg-templates';

export function pageTemplate(params: TemplatePageParam) {
  return axios.post(BASE_URL.concat('/page'), params);
}

export function listTemplate(params: SearchTemplateParam) {
  return axios.post(BASE_URL.concat('/list'), params);
}

export function deleteTemplateById(id: string) {
  return axios.delete(BASE_URL.concat(`/${id}`));
}

export function addTemplate(params: Channel) {
  return axios.post(BASE_URL, params);
}

export function getTemplateById(id: string) {
  return axios.get(BASE_URL.concat(`/${id}`));
}

export function updateTemplateById(id: string, params: Channel) {
  return axios.put(BASE_URL.concat(`/${id}`), params);
}

export interface Channel {
  tenantId?: string;
  id?: string;
  channel?: string;
  enabled?: boolean;
  titleTemplate?: string;
  contentTemplate?: string;
}

export interface SearchTemplateParam {
  name?: string;
  enabled?: boolean;
  templateCode?: string;
}

export type TemplatePageParam = SearchTemplateParam & PageParam;

export type TemplateDetailQueryParam = {
  showMenu?: boolean;
  showButton?: boolean;
};
